home *** CD-ROM | disk | FTP | other *** search
/ BUG 1 / BUGCD1996_0708.ISO / pc / util / minilin / minilin.exe / SBIN / INSTALLP.{_4 < prev    next >
Text File  |  1994-05-22  |  9KB  |  243 lines

  1. #!/bin/sh
  2. # Copyright 1994, Patrick Volkerding, Moorhead, Minnesota USA 
  3. # All rights reserved.
  4. #
  5. # Redistribution and use of this script, with or without modification, is
  6. # permitted provided that the following conditions are met:
  7. #
  8. # 1. Redistributions of this script must retain the above copyright
  9. #    notice, this list of conditions and the following disclaimer.
  10. #
  11. #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  12. #  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  13. #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
  14. #  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  15. #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  16. #  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  17. #  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  18. #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  19. #  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  20. #  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. #
  22. make_install_script() {
  23.  COUNT=1
  24.  LINE="`sed -n "$COUNT p" $1`"
  25.  while [ ! "$LINE" = "" ]; do
  26.   LINKGOESIN="`echo "$LINE" | cut -f 1 -d " "`" 
  27.   LINKGOESIN="`dirname $LINKGOESIN`" 
  28.   LINKNAMEIS="`echo "$LINE" | cut -f 1 -d ' '`"
  29.   LINKNAMEIS="`basename "$LINKNAMEIS"`"
  30.   LINKPOINTSTO="`echo "$LINE" | cut -f 3 -d ' '`"
  31.   echo "( cd $LINKGOESIN ; rm -rf $LINKNAMEIS )"
  32.   echo "( cd $LINKGOESIN ; ln -sf $LINKPOINTSTO $LINKNAMEIS )"
  33.   COUNT=`expr $COUNT + 1`
  34.   LINE="`sed -n "$COUNT p" $1`"
  35.  done
  36. }
  37.  
  38. usage() {
  39.  cat << EOF
  40. Usage: installpkg package_name
  41.        installpkg -warn package_name
  42.        installpkg -r package_name
  43.        installpkg -m package_name
  44.  
  45. Usually used to install a .tgz or .tar.gz package like this:
  46.    installpkg xf_bin.tgz
  47.  
  48. -warn does not install, but tells you what would be deleted or overwritten.
  49.  
  50. You can also install recursively from the current location, like this:
  51.    installpkg -r uucp
  52.  
  53. It is also possible to make a "*.tgz" package with a command like this:
  54.    installpkg -m uucp
  55.    (When you use "-m", the package will not be installed.)
  56.  
  57. In this case, everything from the current directory and all subdirectories
  58. will be copied onto / as a package. The appropriate files under
  59. /var/adm/packages and /var/adm/scripts will be created for a new package
  60. called "uucp", and you will be able to review/remove the package just as 
  61. easily as any other Slackware package. 
  62.  
  63. EOF
  64. }
  65.  
  66. # These tests, while by no means exhaustive, will give a usage message
  67. # and exit with a wide range of bad input.
  68.  
  69. if [ "$1" = "-warn" -a -f "$2" ]; then # -warn
  70.  echo "Scanning the contents of $2..."
  71.  echo
  72.  mkdir -p /tmp/scan
  73.  ( cd /tmp/scan ; tar xzf - install/doinst.sh ) < $2 2> /dev/null 
  74.  if [ -r /tmp/scan/install/doinst.sh ]; then
  75.   if cat /tmp/scan/install/doinst.sh | fgrep 'rm -rf' 1>/dev/null 2>/dev/null ; then
  76.    cat /tmp/scan/install/doinst.sh | fgrep 'rm -rf' > /tmp/scan/install/delete
  77.    echo "The following locations will be completely WIPED OUT to allow symbolic"
  78.    echo "links to be made. (We're talking 'rm -rf') These locations may be files,"
  79.    echo "or entire directories."
  80.    echo
  81.    echo "Be sure you've backed up anything at these locations that you want to"
  82.    echo "save before you install this package:"
  83.    echo
  84.    cat /tmp/scan/install/delete | cut -f 3,7 -d ' ' | tr ' ' '/'
  85.   fi
  86.   if [ -d /tmp/scan ]; then
  87.    ( cd /tmp/scan ; rm -rf install ) 2> /dev/null
  88.    ( cd /tmp ; rmdir scan ) 2> /dev/null
  89.   fi
  90.  fi
  91.  echo
  92.  echo "The following files will be overwritten when installing this package."
  93.  echo "Be sure they aren't important before you install this package:"
  94.  echo
  95.  ( tar tzvvf - ) < $2 | fgrep -v 'drwx'
  96.  echo "You've been warned."
  97.  exit
  98. fi
  99. if [ $# = 2 -a ! "$1" = "-m" -a ! "$1" = "-r" -a ! -r "$1" ]; then
  100.  usage;
  101.  exit
  102. elif [ $# = 0 ]; then
  103.  usage;
  104.  exit
  105. fi
  106. if [ $# = 1 -a ! -r "$1" ]; then
  107.  echo "Package not found: $1"
  108.  echo
  109.  usage;
  110.  exit
  111. fi
  112. if [ "$1" = "-r" -o "$1" = "-m" ]; then
  113.  if [ -r "/var/adm/packages/$2" -a ! "$1" = "-m" ]; then
  114.   echo
  115.   echo "Hey - there's already a package named '$2'! You really should remove"
  116.   echo "that before attempting to install another package with that name,"
  117.   echo "since the old indexes for that package will be overwritten and you'll"
  118.   echo "have to remove any leftover files and links manually."
  119.   echo
  120.   echo -n "Do you want to exit ([y]es, [n]o)? "
  121.   read EXIT;
  122.   if [ "$EXIT" = "y" ]; then
  123.    exit
  124.   fi
  125.  fi
  126.  echo
  127.  echo "Do you want to convert the symbolic links in this package into an"
  128.  echo "installation script named ./install/doinst.sh? If you do, the symbolic"
  129.  echo "links will be removed. You can get them back easily, though, by typing"
  130.  echo 
  131.  echo "sh install/doinst.sh"
  132.  echo
  133.  echo "in the package's root directory."
  134.  echo
  135.  echo "It is recommended that you convert your links for best results."
  136.  echo
  137.  echo -n "Convert links to an install script ([y]es, [n]o)? "
  138.  read CONVERT_LINKS;
  139.  echo
  140.  if [ "$CONVERT_LINKS" = "y" ]; then
  141.   echo "Having a good look at your symbolic links..."
  142.   echo
  143.   find . -type l -exec ls -l {} \; | cut -b58- | tee /tmp/iNsT-a.$$
  144.   echo
  145.   if [ ! -d install ]; then
  146.    mkdir install
  147.   fi
  148.   if [ -r install/doinst.sh ]; then
  149.     cat << EOF
  150. You already have an installation script named install/doinst.sh.
  151. You have 3 choices:
  152.  
  153. 1 - append the script code to create these links (if any) to the end of the
  154.     existing installation script.
  155. 2 - erase the existing installation script, and replace it with the
  156.     code to create these new links.
  157. 3 - Abort! Exit this script.
  158.  
  159. EOF
  160.    echo -n "Which choice would you like (1,2,3)? "
  161.    read DOINST;
  162.    if [ "$DOINST" = "1" ]; then
  163.     echo "Appending to existing script..."
  164.     echo
  165.     make_install_script /tmp/iNsT-a.$$ | tee --append install/doinst.sh
  166.    elif [ "$DOINST" = "2" ]; then
  167.     echo "Replacing existing script..."
  168.     echo
  169.     make_install_script /tmp/iNsT-a.$$ | tee install/doinst.sh
  170.    else
  171.     rm -f /tmp/iNsT-a.$$
  172.     exit
  173.    fi
  174.   else # no script exists:
  175.    echo "Making your install script..."
  176.    echo
  177.    make_install_script /tmp/iNsT-a.$$ | tee install/doinst.sh
  178.   fi # is there already a script?
  179.   rm -f /tmp/iNsT-a.$$
  180.   echo
  181.   echo "Removing the symbolic links:"
  182.   echo
  183.   find . -type l -print -exec rm {} \;
  184.   echo
  185.  fi # make install script?
  186.  # Install the package:
  187.  if [ "$1" = "-r" ]; then # install
  188.   if [ -r install/doinst.sh ]; then # hey, did we do anything?
  189.    # Put the backup of the script in place
  190.    cp install/doinst.sh /var/adm/scripts/$2
  191.    chmod 755 /var/adm/scripts/$2
  192.   fi
  193.   # Write the filelist out:
  194.   echo "PACKAGE NAME:     $2" > /var/adm/packages/$2
  195.   echo "FILE LIST:" >> /var/adm/packages/$2
  196.   echo "./" >> /var/adm/packages/$2
  197.   find . -type f -print | cut -b3- >> /var/adm/packages/$2
  198.   # Copy the stuff into place:
  199.   echo "Installing your new package onto /..."
  200.   cp -a . /
  201.   ( cd / ; sh install/doinst.sh ; rm install/doinst.sh ; rmdir install )
  202.  elif [ "$1" = "-m" ]; then
  203.   echo "Making $2.tgz..."
  204.   tar czf $2.tgz .
  205.  fi
  206. else # we're just going to try to install each argument as a package:
  207.  for package in $* ; do
  208.   echo -n "Installing package $package... "
  209.   # This stuff looks for symbolic links that also belong to other packages and
  210.   # leaves them in place. That way, if you have a couple package pointing to
  211.   # /usr/include on the cdrom and delete one, you'll still have include files.
  212.   shortname=`basename $package .tgz`
  213.   ADM_DIR="/var/adm" 
  214.   TMP=/tmp
  215.   if [ -r $ADM_DIR/scripts/$shortname ]; then
  216.    cat $ADM_DIR/scripts/$shortname | fgrep 'rm -rf' | sort -u > $TMP/del_link_list
  217.    if [ ! -d $ADM_DIR/removed_scripts ]; then
  218.     mkdir -p $ADM_DIR/removed_scripts
  219.    fi
  220.    mv $ADM_DIR/scripts/$shortname $ADM_DIR/removed_scripts 1> /dev/null 2>&1    
  221.    cat $ADM_DIR/scripts/* | fgrep 'rm -rf' | sort -u > $TMP/required_links
  222.    comm -23 $TMP/del_link_list $TMP/required_links > $TMP/delscript
  223.    ( cd / ; sh $TMP/delscript )
  224.    rm -f $TMP/del_link_list $TMP/required_links $TMP/delscript
  225.   fi
  226.   echo "FILE LIST:" > /var/adm/packages/$shortname
  227.   ( cd / ; tar -xzlpvf - ) < $package >> /var/adm/packages/$shortname
  228.   if [ -f /install/doinst.sh ]; then
  229.    echo -n "executing install script..."
  230.    ( cd / ; sh install/doinst.sh -install; )
  231.   fi 
  232.   # Clean up the mess...
  233.   if [ -d /install ]; then
  234.    cp /install/doinst.sh /var/adm/scripts/$shortname
  235.    chmod 755 /var/adm/scripts/$shortname
  236.    (cd /install ; rm -r -f doin* 1> /dev/null 2>&1 )
  237.    rmdir /install 1> /dev/null 2>&1
  238.   fi
  239.   echo
  240.  done
  241. fi
  242. echo
  243.